﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot.Utility.Extend
{
    public static class BytesExtend
    {
        /// <summary>
        /// 拷贝长度
        /// </summary>
        /// <param name="sourceBytes"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static Byte[] Copy(this Byte[] sourceBytes,int length)
        {
            Byte[] resultBytes=new byte[length];
            Buffer.BlockCopy(sourceBytes, 0, resultBytes, 0, length);
            return resultBytes;
        }

        /// <summary>
        /// 拷贝长度
        /// </summary>
        /// <param name="sourceBytes"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static Byte[] Copy(this Byte[] sourceBytes, int startIndex,int length)
        {
            Byte[] resultBytes = new byte[length];
            Buffer.BlockCopy(sourceBytes, startIndex, resultBytes, 0, length);
            return resultBytes;
        }

        public static void Copy(this Byte[] sourceBytes,ref Byte[] resultBytes)
        {
            Buffer.BlockCopy(sourceBytes, 0, resultBytes, 0, resultBytes.Length);
        }
    }
}
